<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>后台管理系统</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

</head>
<body>
    <!-- 右 -->
    <div class="content">
        <div class="header">
            <h1 class="page-title">商品编辑</h1>
        </div>
        
        <!-- edit form -->
        <form action="/shop/update" method="post" id="tab" enctype="multipart/form-data">
            <ul class="nav nav-tabs">
              <li role="presentation" class="active"><a href="#basic" data-toggle="tab">基本信息</a></li>
              <li role="presentation"><a href="#desc" data-toggle="tab">商品描述</a></li>
              <li role="presentation"><a href="#attr" data-toggle="tab">商品属性</a></li>
              <li role="presentation"><a href="#pics" data-toggle="tab">商品相册</a></li>
            </ul>
            <div class="tab-content">
                <div class="tab-pane fade in active" id="basic">
                    <div class="well">
                        <input type="hidden" name="id" value="{$info.id}">
                        <label>商品名称：</label>
                        <input type="text" name="goods_name" value="{$info.goods_name}" class="input-xlarge">
                        <label>商品价格：</label>
                        <input type="text" name="goods_price" value="{$info.goods_price}" class="input-xlarge">
                        <label>商品数量：</label>
                        <input type="text" name="goods_number" value="{$info.goods_number}" class="input-xlarge">
                        <label>商品logo：</label>
                        <input type="file" name="goods_logo" value="" class="input-xlarge">
                        <input type="hidden" name="old_goods_logo" value="{$info.goods_logo}">
                        <img src="{$info.goods_logo}" style="width: 80px;height: 80px" alt="">
                        <label>商品分类：</label>
                        <select name="" class="input-xlarge">
                            <option value="">请选择一级分类</option>
                        </select>
                        <select name="" class="input-xlarge">
                            <option value="">请选择二级分类</option>
                        </select>
                        <select name="cate_id" class="input-xlarge">
                            <option value="">请选择三级分类</option>
                        </select>
                    </div>
                </div>
                <div class="tab-pane fade in" id="desc">
                    <div class="well">
                        <label>商品简介：</label>
<!--                        容器-->
                        <div id="div1">
                        </div>
<!--                        为了将富文本编辑器的内容传送的服务端-->
                        <textarea value="Smith" name="goods_introduce" rows="3" class="input-xlarge" id="goods_introduce" style="display: none">{$info.goods_introduce}</textarea>
                    </div>
                </div>
                <div class="tab-pane fade in" id="attr">
                    <div class="well">
                        <label>商品类型：</label>
                        <select name="" class="input-xlarge">
                            <option value="2">电脑</option>
                            <option value="1">手机</option>
                        </select>
                        <div>
                            <label>商品品牌：</label>
                            <input type="text" name="" value="edit" class="input-xlarge">
                            <label>商品型号：</label>
                            <input type="text" name="" value="edit" class="input-xlarge">
                            <label>商品重量：</label>
                            <input type="text" name="" value="edit" class="input-xlarge">
                        </div>
                    </div>
                </div>
                <div class="tab-pane fade in" id="pics">
                    <div class="well">
                            <div>[<a href="javascript:void(0);" class="add">+</a>]商品图片：<input type="file" name="goods_pics[]" value="" class="input-xlarge"></div>
                    </div>
                </div>
                <button class="btn btn-primary" type="submit">保存</button>
            </div>
        </form>
        <!-- footer -->
        <footer>
            <hr>
            <p>© 2017 <a href="javascript:void(0);" target="_blank">ADMIN</a></p>
        </footer>
    </div>


    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
    <!-- 引入 wangEditor.min.js -->
    <script src="https://cdn.jsdelivr.net/npm/wangeditor@latest/dist/wangEditor.min.js"></script>

    <script type="text/javascript">
        const E = window.wangEditor
        const editor = new E('#div1')
        const $text1 = $('#goods_introduce')
        editor.config.onchange = function (html) {
            // 第二步，监控变化，同步更新到 textarea
            $text1.val(html)
        }
        // 配置 server 接口地址
        editor.config.uploadImgServer = '/shop/uploadImage'
        editor.create()

        // 初始化容器的内容
        editor.txt.html($text1.text());
        // 第一步，初始化 textarea 的值
        $text1.val(editor.txt.html())
    </script>

    <script type="text/javascript">
        $(function(){
            $('.add').click(function(){
                var add_div = '<div>[<a href="javascript:void(0);" class="sub">-</a>]商品图片：<input type="file" name="goods_pics[]" value="" class="input-xlarge"></div>';
                $(this).parent().after(add_div);
            });
            $('.sub').live('click',function(){
                $(this).parent().remove();
            });
        });
    </script>
</body>
</html>